<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); 

require(APPPATH."libraries/auth/Authenticator.php");

class MySQLAuthenticator extends Authenticator {

	private $dbh;

    function __construct()
    {
        parent::__construct();

    }

    
    function login($username, $password)
    {
		$dbh = mysql_connect(
				$this->CI->config->item('mysql_host'),
				$this->CI->config->item('mysql_user'),
				$this->CI->config->item('mysql_pass')
		);
		if (!$dbh)
		{
			printf("Could not connect to %s\n",  $this->CI->config->item('mysql_host'));
		}
		mysql_select_db( $this->CI->config->item('mysql_db'));
		$sql = sprintf("SELECT * FROM users WHERE username = '%s' AND PASSWORD('%s') = password",
			$username,
			$password
			);
		// print $sql;
		$result = mysql_query($sql);
		if (!$result)
		{
			print "bad result: " . mysql_error();
		}
		$row  =  mysql_fetch_assoc($result);
	    if ($row['username'] === $username)
	    {
			$group = 'test';
            $this->make_session($username, $group);
			return 1;
	    }
	    else
	    {
            return 0;
        }
    }
    
    

    
}

